import { CN, GB, US, DE } from '/@/stores/cityList';
import useCommonState from '/@/utils/pageState/commonState';
const { SITE_DE, SITE_GB, SITE_US } = useCommonState();

export default function () {
	const MAX_LENGTH = 99999999;

	// 是否上架
	const IN_SALE = 1;
	const NO_SALE = 0;
	const SHELF_STATUS = [
		{
			value: '',
			label: '全部',
		},
		{
			value: IN_SALE,
			label: '是',
		},
		{
			value: NO_SALE,
			label: '否',
		},
	];

	// 获取上下架文本
	function getPublishStatusText(params) {
		let text = '';
		switch (params) {
			case IN_SALE:
				text = '上架';
				break;
			case NO_SALE:
				text = '下架';
				break;
			default:
				text = '';
				break;
		}
		return text;
	}

	// 来源
	const IN_EFFECT = 1;
	const EXPIRED = 0;
	const TO_BE_EFFECTIVE = 2;
	const COUPON_STATUS_LIST = [
		{
			value: '',
			label: '全部',
		},
		{
			value: IN_EFFECT,
			label: '生效中',
		},
		{
			value: EXPIRED,
			label: '已过期',
		},
		{
			value: TO_BE_EFFECTIVE,
			label: '待生效',
		},
	];

	// 优惠券规则
	const FULL_MINUS = 2; // 满减
	const DISCOUNT = 1; // 折扣
	const COUPON_RULES_LIST = [
		{
			value: FULL_MINUS,
			label: '满减',
		},
		{
			value: DISCOUNT,
			label: '折扣',
		},
	];

	// 使用商品的选项
	const USE_GOODS_1 = 0;
	const USE_GOODS_2 = 1;
	const USE_GOODS_3 = 2;
	const USE_GOODS_4 = 3;
	const USE_GOODS_LIST = [
		{
			value: USE_GOODS_1,
			label: '全部商品',
		},
		{
			value: USE_GOODS_2,
			label: '选择分类',
		},
		{
			value: USE_GOODS_3,
			label: '搜索商品',
		},
		{
			value: USE_GOODS_4,
			label: '批量导入',
		},
	];

	// 获取生效状态文本
	function getCouponStatusText(params) {
		let text = '';
		switch (params) {
			case IN_EFFECT:
				text = '生效中';
				break;
			case EXPIRED:
				text = '已过期';
				break;
			case TO_BE_EFFECTIVE:
				text = '待生效';
				break;
			default:
				text = '';
				break;
		}
		return text;
	}

	// 返回站点的标识
	function returnPlatform(params) {
		let state = SITE_DE;
		switch (params) {
			case GB:
				state = SITE_GB;
				break;
			case US:
				state = SITE_US;
				break;
			case DE:
				state = SITE_DE;
				break;
			default:
				state = SITE_DE;
				break;
		}
		return state;
	}

	// 根据站点返回对应的国家
	function returnCountryByPlatform(params) {
		let state = '';
		switch (params) {
			case SITE_GB:
				state = GB;
				break;
			case SITE_US:
				state = US;
				break;
			case SITE_DE:
				state = DE;
				break;
			default:
				state = '';
				break;
		}
		return state;
	}

	// 获取优惠券文本
	function getCouponRulesText(params) {
		let text = '';
		switch (params) {
			case FULL_MINUS:
				text = '满减';
				break;
			case DISCOUNT:
				text = '折扣';
				break;
			default:
				text = '';
				break;
		}
		return text;
	}

	// 获取国家货币字符
	function getCurrencySymbolText(params) {
		let text = '';
		switch (params) {
			case CN:
				text = '￥';
				break;
			case GB:
				text = '￡';
				break;
			case US:
				text = '$';
				break;
			case DE:
				text = '€';
				break;
			default:
				text = '';
				break;
		}
		return text;
	}

	// 获取国家货币字符
	function getCurrencySymbolTextBySite(params) {
		let platform = returnCountryByPlatform(params);
		let text = '';
		text = getCurrencySymbolText(platform);
		return text;
	}

	// 根据字段返回不同的价格文本
	function getPriceByField(params, completeString, cuttingStrig = 'Price') {
		let text = '';
		let cutString = completeString.split(cuttingStrig) ? completeString.split(cuttingStrig)[0] : '';
		// 这里拿到的cutString为eu，uk，us
		switch (cutString) {
			case 'eu':
				text = getCurrencySymbolText(DE);
				break;
			case 'uk':
				text = getCurrencySymbolText(GB);
				break;
			case 'us':
				text = getCurrencySymbolText(US);
				break;

			default:
				text = '';
				break;
		}
		return params ? text + params : text + '0';
	}

	// 根据优惠券类型返回不同的折扣/优惠金额
	function getPreferentialamount(rule, params) {
		let text = '';
		switch (rule) {
			case DISCOUNT:
				text = (params ? params : `0`) + '折';
				break;
			case FULL_MINUS:
				text = '减' + (params ? params : `0`);
				break;
			default:
				text = '';
				break;
		}
		return text;
	}

	return {
		MAX_LENGTH,
		IN_SALE,
		NO_SALE,
		SHELF_STATUS,
		IN_EFFECT,
		EXPIRED,
		TO_BE_EFFECTIVE,
		COUPON_STATUS_LIST,
		FULL_MINUS,
		DISCOUNT,
		COUPON_RULES_LIST,
		USE_GOODS_1,
		USE_GOODS_2,
		USE_GOODS_3,
		USE_GOODS_4,
		USE_GOODS_LIST,
		getPublishStatusText,
		getCouponStatusText,
		returnPlatform,
		getCouponRulesText,
		getCurrencySymbolText,
		getCurrencySymbolTextBySite,
		getPriceByField,
		getPreferentialamount,
	};
}
